<?php

namespace App\Service\UserCenter\v1_0_8;

use App\Constants\ErrorCode;
use App\Model\UserProfile;
use App\Model\UserProfilePersonal;
use App\Model\WhiteHost;
use App\Service\BaseService;

/**
 * 提现检测
 */
class WithdrawCheckService extends BaseService
{
    public function handle()
    {
        $userId = $this->getUserId();
        $user = $this->getUser();
        if (!$user->phone) {
            return $this->setError(ErrorCode::PHONE_NOT_BIND, '你还没有绑定手机号，请先绑定~');
        }
        $personInfo = UserProfilePersonal::getProfile($userId);

        if (!UserProfile::checkAvatarVrfied($userId)) {
            return $this->setError(ErrorCode::REAL_AVATAR_NOT_VRFY, '还未通过真人头像认证～');
        }

        $version = $this->request->input('version', '');
        if (version_compare($version, '1.0.7', '<')) {
            if (!UserProfilePersonal::isFaceVerified($personInfo)) {
                return $this->setError(ErrorCode::NO_FACE_VRFY, '请先完成实名认证～（如在认证审核中，请通过审核后再提现哦！）');
            }

            if (UserProfilePersonal::checkVerifing($userId, $personInfo)) {
                return $this->setError(ErrorCode::ID_VRFYING, "你的实名信息正在审核中，请等待人工审核通过后再操作～");
            }
            //是否已经姓名身份认证
            if (!UserProfilePersonal::isRealnameVerified($personInfo)) {
                return $this->setError(ErrorCode::NO_ID_VRFY, '你还未进行身份验证!');
            }
            //是否已经刷脸认证
            elseif (!UserProfilePersonal::isFaceVerified($personInfo)) {
                return $this->setError(ErrorCode::NO_FACE_VRFY, '你还未进行视频刷脸验证!');
            }
            //是否绑定收款账号
            elseif (!UserProfilePersonal::isBindAccount($personInfo)) {
                return $this->setError(ErrorCode::NO_BIND_ACCOUNT, '请先绑定收款账号!');
            }
        }

        return [
            'check_result' => 1
        ];
    }
}
